<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>已审批产品列表---审批人</title>
    <script type="text/javascript">
      var editProductWin;
      var newPurchaseWin;
      var productId;
      Ext.onReady(function(){
        //产品列表---------------------------------------------------------
        //生成有关客户的Grid
        var productDS = new Ext.data.Store({
          autoLoad :{params : {start:0,limit : pageSize}},
          proxy: new Ext.data.HttpProxy({
            url: '/product/getAuditedProducts'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'vendor_name',
              mapping: 'vendor.company_name'
            }, {
              name: 'name'
            }, {
              name: 'model'
            }, {
              name: 'specification'
            }, {
              name: 'manufacturer'
            }, {
              name: 'unit_price'
            }, {
              name: 'brand'
            }])
        });
        var productSM = new Ext.grid.CheckboxSelectionModel();
        var productCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),productSM,{
            header: '产品名称',
            dataIndex: 'name',
            width:180
          },{
            header: '供应商',
            dataIndex: 'vendor_name',
            width:180
          }, {
            header: '品牌',
            dataIndex: 'brand',
            width:60
          }, {
            header: '型号',
            dataIndex: 'model',
            width:130
          }, {
            header: '规格',
            dataIndex: 'specification',
            width:80
          }, {
            header: '生产商',
            dataIndex: 'manufacturer',
            width:130
          }, {
            header: '单价',
            dataIndex: 'unit_price',
            width:60
          }]);
        var productGrid =  new Ext.grid.GridPanel({
          ds: productDS,
          cm: productCM,
          sm: productSM,
          width: screenWidth-330,
          height: screenHeight-320,
          iconCls: 'icon-grid',loadMask: true,
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '客户列表',
          tbar:['-',
            {
              text: '查看产品',
              width:50,
              iconCls:'editItem',
              handler:function(){
                var records = productGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再查看。');
                }else{
                  //把表单添加到窗口中
                  productId = records[0].get('id');
                  productViewWin = new Ext.Window({
                    title: '查看产品信息',
                    layout:'fit',
                    width:623,
                    height:435,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    //autoScoll:true,
                    autoLoad: {
                      url: "/product/productOnlyView?id=" + productId,
                      scripts: true
                    }
                  });
                  productViewWin.on("destroy",function(){
                    productDS.reload();
                  });
                  productViewWin.resizable = false;
                  productViewWin.show();
                }
              }
            },{
              text: '申购产品',
              iconCls: 'addItem',
              handler : function(){
                var records = productGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请选择要申购的产品。');
                }else{
                  productId = records[0].get('id');
                  newPurchaseWin = new Ext.Window({
                    layout: 'fit',
                    width:775,
                    height:498,
                    closeAction: 'destroy',
                    plain: true,
                    modal: true,
                    constrain:true,
                    //modal: true,
                    title: '新增申购单',
                    autoLoad: {
                      url: "/purchase/newPurchaseForProduct?id="+productId,
                      scripts: true
                    }
                  });
                  newPurchaseWin.resizable = false;
                  newPurchaseWin.show();
                }
              }
            },'-','检索条件','-',
            '产品名称',
            new Ext.form.TextField({
              name: 'product_name',
              width:100,
              id: 'product_name'
            }),
            '供应商名称',
            new Ext.form.TextField({
              name: 'vendor_name',
              width:100,
              id: 'vendor_name'
            }),
            {
              text:'搜索',
              iconCls:'search',
              handler:function(){
                productDS.removeAll();
                productDS.baseParams.product_name = Ext.getCmp('product_name').getValue()
                productDS.baseParams.vendor_name = Ext.get('vendor_name').getValue()
                productDS.load();
              }
            }
          ],
          bbar: new Ext.PagingToolbar({
            //start:0,
            //limit:1,
            pageSize: pageSize,
            store: productDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });
        productDS.load();
        productGrid.render('product_list');
      })
    </script>
  </head>
  <body>
    <div id="product_list"></div>
  </body>
</html>
